package com.atguigu.day16.homework.h1;

import java.util.Arrays;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/19 20:00
 * @注释
 */
public class HomeWork01 {
    public static void main(String[] args) {
        double[] arr = new double[10];
        for (int i = 0; i < arr.length - 1; i++){
            arr[i] = Math.random() * 100;
        }
        arr[arr.length - 1] = 0;
        System.out.println("直线上每一个点到后一个点的距离:" + Arrays.toString(arr));

        double length = 100.5;

        int max = 0;
        for (int i = 0; i < arr.length; i++){
            int count = 0;
            double sum = 0;
            if(max < arr.length - i){
                for(int j = i; j < arr.length; j++){
                    sum += arr[j];
                    if(sum <= length){
                        count++;
                    }else{
                        break;
                    }
                }
                System.out.println("count = " + count);
                if(count > max){
                    max = count;
                }
            }
        }
        System.out.println("长度为:" + length + "的绳子最多能覆盖" + max + "个点");
    }
}
